//
//  VideoHeaderView.m
//  Four_Fit
//
//  Created by xalo on 16/7/13.
//  Copyright © 2016年 xmaz. All rights reserved.
//

#import "VideoHeaderView.h"

@interface VideoHeaderView ()
{
    CAShapeLayer *frameShape; //本周热门的边框
}
@property (weak, nonatomic) IBOutlet UIView *bgView;

@end

@implementation VideoHeaderView

- (void)awakeFromNib {
    // Initialization code
}
- (void)setCarouselTagName:(UILabel *)carouselTagName{
    _carouselTagName.text = carouselTagName.text;
    [self.bgView layoutIfNeeded];
    //边框
    UIBezierPath *Frame = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 1, self.bgView.frame.size.width, self.bgView.frame.size.height) cornerRadius:5];
    frameShape = [[CAShapeLayer alloc] init];
    frameShape.path = Frame.CGPath;
    frameShape.lineWidth = 1.0;
    frameShape.strokeColor = [UIColor whiteColor].CGColor;
    frameShape.fillColor = [UIColor clearColor].CGColor;
    frameShape.strokeEnd = 0;
    [self.bgView.layer addSublayer:frameShape];
    //星星
    UIBezierPath *starPath = [UIBezierPath bezierPath];
    [starPath moveToPoint:CGPointMake(17, 5)];
    [starPath addLineToPoint:CGPointMake(14.30576, 13.29176)];
    [starPath addLineToPoint:CGPointMake(5.5873, 13.29176)];
    [starPath addLineToPoint:CGPointMake(12.64064, 18.41648)];
    [starPath addLineToPoint:CGPointMake(9.94652, 26.70824)];
    [starPath addLineToPoint:CGPointMake(17, 21.58364)];
    [starPath addLineToPoint:CGPointMake(24.05348, 26.70824)];
    [starPath addLineToPoint:CGPointMake(21.35936, 18.41648)];
    [starPath addLineToPoint:CGPointMake(28.41272, 13.29176)];
    [starPath addLineToPoint:CGPointMake(19.69424, 13.29176)];
    [starPath addLineToPoint:CGPointMake(17, 5)];
    CAShapeLayer *starLayer = [[CAShapeLayer alloc] init];
    starLayer.path = starPath.CGPath;
    starLayer.fillColor = [UIColor whiteColor].CGColor;
    [self.bgView.layer addSublayer:starLayer];
    
    //定时器让边框动
    [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timeAction) userInfo:nil repeats:YES];
}

- (void)timeAction{
    if(frameShape.strokeEnd > 1 && frameShape.strokeStart < 1)
    {
        frameShape.strokeStart += 0.03;
    }
    else
        if (frameShape.strokeStart == 0)
        {
            frameShape.strokeEnd += 0.03;
        }
    if (frameShape.strokeEnd == 0)
    {
        frameShape.strokeStart = 0;
    }
    if (frameShape.strokeStart == frameShape.strokeEnd)
    {
        frameShape.strokeEnd = 0;
    }
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.delegate goAway];
}
@end
